package com.lin.fengxiu.api.v1;


import com.lin.fengxiu.exception.http.NotFoundException;
import com.lin.fengxiu.model.Activity;
import com.lin.fengxiu.service.ActivityService;
import com.lin.fengxiu.vo.ActivityCouponVO;
import com.lin.fengxiu.vo.ActivityPureVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ActivityService
 * @Description TODO
 * @Author wushaopei
 * @Date 2021/3/23 23:54
 * @Version 1.0
 */
@RequestMapping("activity")
@RestController
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * @Description TODO 为首页活动提供封面
     * @param name
     * @return
     */
    @GetMapping("/name/{name}")
    public ActivityPureVO getHomeActivity(@PathVariable String name){
        Activity activity = activityService.getByName(name);
        if(activity == null){
            throw new NotFoundException(40001);
        }
        ActivityPureVO vo = new ActivityPureVO(activity);
        return vo;
    }

    /**
     * @Description TODO 首页优惠券活动入口
     * @param name
     * @return
     */
    @GetMapping("/name/{name}/with_coupon")
    public ActivityCouponVO getActivityWithCoupons(@PathVariable String name){
        Activity activity = activityService.getByName(name);
        if(activity == null){
            throw new NotFoundException(40001);
        }
        return new ActivityCouponVO(activity);
    }
}
